<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>列表</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/yzl.css"/>

    <style>
    </style>
</head>
<body>

<div id="app" v-cloak>
    <div class="my-order-body" v-if="shareGoodsList.length==0">
        <div style="text-align:center;padding-top: 60px;">
            <div style="text-align:center;padding-top: 70px;">
                <img v-src="'../../image/not_available.png'" width="70px" height="70px"/>
                <div style="padding-top:10px ">
                    <span>没找到您要的商品</span>
                </div>
            </div>
        </div>
    </div>
    <div style="padding-top: 5px;width:95%;margin:0 auto;" v-show="shareGoodsList.length>0">
         <div class="share-container" v-for="(good,index) in shareGoodsList" :key="good.goods_id" style="border-radius:10px">
         <div class="share-single">
           <div class="share-goods-left" v-myclick="[good.goods_id, getGoodsInfo]">
            <img v-image-resize="{src:good.pic}" :key="good.goods_id">
          <!-- <div class="share_button_container">
            <span class="share_collect">收藏:{{good.collect_count>999?999+'+':good.collect_count}}</span><span class="share_share">分享:{{good.share_count>999?999+'+':good.share_count}}</span>
          </div> -->
           </div>
           <div class="share-goods-right">
             <p v-myclick="[good.goods_id, getGoodsInfo]" class="share-title">{{good.title}}</p>
             <p v-myclick="[good.goods_id, getGoodsInfo]" class="share-describe">{{good.description?good.description:'【友人店推荐】超值精选品，价好、物好，你值得拥有。你的优质生活，我们来打造。'}}</p>
             <div class="share-price">
               <div style="float:left;background:#F9F0F5;color:#9D0152;line-height:100%;padding:4px 10px;border-radius:4px">赚：{{member_type==6?good.t6_gain_max:good.t5_gain_max}}</div>
               <div style="float:right;background:#9D0152;width:60px;height:18px;padding:2px;font-size:12px;color:#ffffff;border-radius:4px">
                 <div style="float:left;line-height:18px;background:#ffffff;color:#9D0152;width:20px;text-align:center;border-radius:2px">券</div>
                 <div style="float:left;padding-left:2px;line-height:18px;text-align:center;width:36px;overflow:hidden">{{parseInt(good.coupon_amount)}}元</div>
               </div>
               <div style="clear:both"></div>
             </div>
             <div class="share-coupon">
               <div class="share_coupon_container">
               <div class="share_goods_price">￥{{good.price}}</div>
               <div class="share_diate" v-myclick="[{share:good.share,goods_id:good.goods_id}, share]">立即分享</div>
               <div style="clear:both"></div>
             </div>
           </div>
           </div>
           <div style="clear:both"></div>
         </div>
       </div>
    </div>
    <lazy-load v-if="shareGoodsList.length > 0" style="background-color:#f7f7f7;margin:10px 0;"
               count-per-page="20"
               :arr="shareGoodsList"
               :url="url"
               ret-attr="homeGoods"
               >
    </lazy-load>
</div>
<script src="../../script/api.js"></script>
<script src="../../script/vue.js"></script>
<script src="../../script/app.js"></script>
<script src="../../script/url.js"></script>
<script src="../../script/common.js"></script>
<script src="../../script/components.js"></script>
<script>
    var vm;
    var wx;
    var shareGoodsList;
    var member_type;
    apiready = function () {
        setBSImg();
        showProgress();
        MNActionButton = api.require('PIActionButton');
        wx = api.require('wx');
        var data = {
            member_id: getPrefs('member_id')
        };
        var callback = function (ret) {
            var home = ret.content;
            shareGoodsList = home.homeGoods;
            if (getPrefs('token')) {
              user = JSON.parse(getPrefs('user'));
              member_type = user.member_type;
            }
            initApp();
            api.parseTapmode();
        };
        pinet.post(URL.getShareGoods, data, callback);
        addListeners();
        setRefreshHeaderInfo(refresh);
        addListeners();
    };

    function refresh() {
        var data = {
            member_id: getPrefs('member_id')
        };
        var callback = function (ret) {
            var home = ret.content;
            shareGoodsList = home.homeGoods;
            if (getPrefs('token')) {
              user = JSON.parse(getPrefs('user'));
              member_type = user.member_type;
            }
            if (vm) {
                vm.shareGoodsList = shareGoodsList;
                vm.key++;
            }else{
                initApp();
            }
            api.refreshHeaderLoadDone();
        };
        var errback = function () {
            api.refreshHeaderLoadDone();
        };
        pinet.post(URL.getShareGoods, data, callback, errback);
    }

    function initApp() {
        var isBigImg = Vue.BSImg == 'big';
        vm = new Vue({
            el: '#app',
            data: {
                url:URL.getShareGoods,
                BSImg: {
                    big: isBigImg,
                    small: !isBigImg
                },
                shareGoodsList: shareGoodsList,
                member_type:member_type
            },
            methods: {
              openGoodsDetail: function (goods_id) {
                  if(!getPrefs('token')){
                      reLogin();
                  }else{
                    openWin('../home/browser', {goods_id: goods_id});
                  }
              },
              getGoodsInfo: function (goods_id) {
                  var attributes = {
                      goods_id: goods_id
                  };
                  onEvent('t004_c006','精选-商品',attributes);
                  openWin('share_info', {goods_id: goods_id});
              },
              share: function (infos) {
                  if(!getPrefs('token')){
                      reLogin();
                  }else{
                    share = infos.share;
                    var sharestr = share.url;
                    var tempstr = sharestr.split("&");
                    for(var i=0;i<tempstr.length;i++){
                      var iscloud = tempstr[i].indexOf("member_id=");
                      if(iscloud>=0){
                        var old_member_id = tempstr[i].split("=")[1];
                        break;
                      }
                    }
                    var member_id = getPrefs('member_id');
                    if(old_member_id!==member_id){
                      var str1 = sharestr.replace('member_id='+old_member_id, 'member_id='+member_id);
                      share.url  = str1;
                    }
                    var attributes = {
                        goods_id:infos.goods_id
                    };
                    var sharesuffix = {
                      eventId:'t001_c001_a004',
                      eventLable:'精选-商品-列表-分享',
                      attributes:attributes
                    }
                   //  onEvent('t002_c003_a001','抢购-时段-商品-购买',attributes);
                    openMNActionButton(share,sharesuffix);
                  }
              },
            },
        });
    }

    function addListeners() {
        api.addEventListener({
            name: 'share'
        }, function () {
            window.location.reload();
        });
        api.addEventListener({
            name: 'viewappear'
        }, function () {
            onPageStart();
        });

        api.addEventListener({
            name: 'viewdisappear'
        }, function (ret, err) {
            onPageEnd();
        });

        api.addEventListener({
            name: 'keyback'
        }, function (ret, err) {
            onPageEnd();
            api.closeWin();
        });
    }

</script>
</body>
</html>
